﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace MyRecipeBook.UI.Controls.DashboardItems
{
    /// <summary>
    /// Interaction logic for ControlDashboardItemClock.xaml
    /// </summary>
    public partial class ControlDashboardItemClock : UserControl
    {
        private readonly DispatcherTimer _timer;

        public ControlDashboardItemClock()
        {
            _timer = new DispatcherTimer {Interval = TimeSpan.FromSeconds(1)};
            _timer.Tick += TimerTick;

            InitializeComponent();

            _timer.Start();
        }

        void TimerTick(object sender, EventArgs e)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
            {
                SecondHand.Angle = DateTime.Now.Second * 6;
                MinuteHand.Angle = DateTime.Now.Minute * 6;
                HourHand.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5);
            }));

        }
    }
}
